package com.example.conference.mapper;

import com.example.conference.domain.CourseStudent;
import com.example.conference.domain.vo.CourseStudentInfo;
import com.example.conference.domain.vo.CourseStudentInfoVo;
import com.example.conference.domain.vo.CourseStudentVo;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CourseStudentMapper {
    @Select("select * from course_student")
    List<CourseStudent> queryAll();

    @Select("select * from course_student where ct_id = #{ctId}")
    List<CourseStudent> queryByctId(Integer ctId);

    @Select("select * from course_student where ct_id = #{ctId}")
    @Results(id = "studentInfo", value= {
            @Result(column="user_id", property="student" ,
                    one=@One(select="com.example.conference.mapper.UserMapper.queryByIdToVo")),
    })
    Page<CourseStudentInfo> queryByctIdToStudentInfo(Integer ctId);

    @Select("select user_id from user where user_id = #{userId}")
    @Results(value= {
            @Result(column="user_id", property="student" ,
                    one=@One(select="com.example.conference.mapper.UserMapper.queryByIdToVo")),
            @Result(column="user_id", property="courseStudentVoList" ,
                    many=@Many(select="com.example.conference.mapper.CourseStudentMapper.queryByStudent")),
    })
    Page<CourseStudentInfoVo> queryByStudentToList(Integer userId);

    @Select("select * from course_student where user_id = #{userId}")
    @Results(value= {
            @Result(column="ct_id", property="courseTeacherVo" ,
                    one=@One(select="com.example.conference.mapper.CourseTeacherMapper.queryByIdToMap")),
        })
    List<CourseStudentVo> queryByStudent(Integer userId);



    @Insert("insert into course_student (user_id,ct_id) VALUES (#{userId}, #{ctId})")
    Integer add(CourseStudent courseStudent);

    @Select("select * from course_student where ct_id = #{ctId} and user_id = #{userId}")
    Integer check(CourseStudent courseStudent);

    @Update("update course_student Set grade = #{grade} where cs_id = #{csId}")
    Integer update(CourseStudent courseStudent);

    @Delete("delete from course_student where cs_id = #{csId}")
    Integer delete(Integer csId);

    @Select("select ct_id from course_student where cs_id = #{csId}")
    Integer queryctIdBycsId(Integer csId);

}